<?php
/**
 * Created by PhpStorm.
 * User: hhl91
 * Date: 2019/4/2
 * Time: 22:48
 * detail: 流程控制语句
 */
    namespace vender\models1;
    $num=rand(1,20);
    echo '$num='.$num;
    if ($num%2==0){
        echo "<br>$num 是偶数:".$num.'<br>';//这里除了一个问问题”$num是偶数“这样输出不出来汉字，在”“$num后面加一个空格就好了
    }
    //p57页练一练
    ////
    function check_cet4($sorces){
        if ($sorces>=425){
            echo "这位同学你成功的通过了四级<br>";
        }else{
            echo "同学你要不断的努力啊<br>";
        }
    }
    echo "这位同学考试得了 666分<br>";
    check_cet4(666);
        /////
    $new=rand(1,40);
    if ($new==1){
        echo "一等奖，奖品为42寸电视机<br>";
    }elseif ($new>2 && $new<5){
        echo "二等奖，奖品为光波炉<br>";
    }elseif ($new>5&&$new<10){
        echo "三等奖，奖品是加湿器<br>";
    }elseif($new>10&&$new<20){
        echo "四等奖，四大等奖是16G-U盘<br>";
    }else{
        echo "很遗憾你未中奖<br>";
    }

    namespace vender\models2;
    $string="明日科技";
    echo substr($string,0,7);//一个汉字占三个字节

    $row1="11.5 继承泛型类与实现泛型类接口下";
    $row2="11.4 继承泛型类与实现泛型类接口上";
    $row3="11.3 限制泛型；反省通配符";
    $row4="11.2 限制泛型；反省继承类和接口";
    $row5="11.1 限制泛型；泛型类";
    $row6="11.7 限制泛型；枚举实现接口";
    $row7="11.6 限制泛型；枚举的类成员";
    /** 顶i字符串截取函数**/
    function getSubstr($string){
        if (mb_strlen($string,"UTF-8") > 15){/**Fatal error: Uncaught Error: Call to undefined function vender\models2\mb_strlen() in C:\Users\hhl91\PhpstormProjects\text\流程控制语句.php:57 Stack trace: #0 C:\Users\hhl91\PhpstormProjects\text\流程控制语句.php(65): vender\models2\getSubstr('11.5 \xE7\xBB\xA7\xE6\x89\xBF\xE6\xB3\x9B\xE5...') #1 {main} thrown in C:\Users\hhl91\PhpstormProjects\text\流程控制语句.php on line 57**/
            echo mb_substr($string,0,15,"UTF-8")."...";
        }else{
            echo $string;
        }
        echo "<br>";
    }
    /** 调用getSubstr函数，输出结果**/
    getSubstr($row1);
    getSubstr($row2);
    getSubstr($row3);
    getSubstr($row4);
    getSubstr($row5);
    getSubstr($row6);
    getSubstr($row7);

?>